package com.D5Power.Editor
{
	import com.D5Power.ns.D5Map;
	
	import flash.events.Event;
	
	import org.aswing.JButton;
	import org.aswing.JLabel;
	import org.aswing.JPanel;
	import org.aswing.JTextField;
	import org.aswing.LayoutManager;
	import org.aswing.border.TitledBorder;
	import org.aswing.ext.Form;
	
	use namespace D5Map;
	/**
	 * 地图属性
	 */ 
	public class MapProperty extends JPanel
	{
		private var _root:D5RpgEditor;
		
		private var _box:Form;
		private var _loopfile:JTextField;
		private var _luafile:JTextField;
		private var _scenefile:JTextField;
		
		public function MapProperty(layout:LayoutManager=null,editor:D5RpgEditor=null)
		{
			_root = editor;
			super(layout);
			init();
		}
		
		public function display():void
		{
			_loopfile.setText(_root.Shower.scene.Map.loopBG);
		}
		
		private function init():void
		{
			_box = new Form();
			
			// 增加循环背景控制
			_loopfile = new JTextField('',10);
			var lable:JLabel = new JLabel('背景：',null,JLabel.LEFT);
			lable.setToolTipText("请输入一个asset目录下的文件路径作为循环背景。");
			var bt:JButton = new JButton('更新');
			bt.addActionListener(updateLoopBG);
			
			// 场景地图
			_scenefile = new JTextField('',10);
			var lable0:JLabel = new JLabel('场景：',null,JLabel.LEFT);
			var bt0:JButton = new JButton('更新');
			bt0.addActionListener(updateSceneBG);
			
			// 增加Lua脚本控制
			_luafile = new JTextField('',10);
			var lable1:JLabel = new JLabel('脚本：',null,JLabel.LEFT);
			var bt1:JButton = new JButton('编辑');
			bt1.addActionListener(updateLua);
			
			
			_box.addRow(lable,_loopfile,bt);
			_box.addRow(lable0,_scenefile,bt0);
			_box.addRow(lable1,_luafile,bt1);
			
			_box.setSizeWH(D5Power.SMALLMAPSIZE,200);
			append(_box);
			
			setBorder(new TitledBorder(null,'参数设置',TitledBorder.TOP,TitledBorder.LEFT,4));
		}
		
		/**
		 * 更新循环背景
		 */ 
		private function updateLoopBG(e:Event):void
		{
			if(_loopfile.getText()!=_root.Shower.scene.Map.loopBG && _loopfile.getText()!='')
			{
				_root.Shower.scene.Map.loopBG = _loopfile.getText();
			}
		}
		
		/**
		 * 更新场景地图
		 */ 
		protected function updateSceneBG(e:Event=null):void
		{
			if(_scenefile.getText()=='') return;
			_root.Shower.scene.Map.tileFormat=_scenefile.getText();
			_root.Shower.scene.Map.flushMap();
		}
		/**
		 * 外部调用更新地图场景
		 */ 
		public function setSceneBG(s:String):void
		{
			s = s.replace('.','');
			if(s!='jpg' && s!='png') return;
			_scenefile.setText(s);
			updateSceneBG(null);
		}
		
		/**
		 * 更新场景脚本
		 */ 
		private function updateLua(e:Event):void
		{
			var luaE:LuaEditor = new LuaEditor(_root.Window,_luafile.getText(),_root.Shower,this);
			luaE.show();
		}
		
		public function luaEditorBack(fname:String):void
		{
			_root.Shower.scene.lua_file=fname;
		}
		
		public function updateBGName(s:String):void
		{
			_loopfile.setText(s);
		}
		
		public function updateLuaName(s:String):void
		{
			_luafile.setText(s);	
		}
		
		public function reset():void
		{
			
		}
		
		
	}
}